﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Service.BAL;

namespace Service.DAL
{
    public class NhapHang_DAL
    {
        public static List<NhapHang_BAL> GetAll()
        {
            List<NhapHang_BAL> result = new List<NhapHang_BAL>();
            try
            {
                var phieuNH = from pnh in Common_DAL.storeData.PhieuNhapHangs
                             select new NhapHang_BAL()
                             {
                                 MaNhapHang = pnh.MaNhapHang,
                                 TrangThai = (int)pnh.TrangThai    
                             };
                result = phieuNH.ToList<NhapHang_BAL>();
            }
            catch
            {

            }
            return result;
        }

        public static List<NhapHang_BAL> GetAllByID(string strMaPhieuNhap)
        {
            List<NhapHang_BAL> result = new List<NhapHang_BAL>();
            try
            {
                var phieuNH = from pnh in Common_DAL.storeData.PhieuNhapHangs
                              where pnh.MaNhapHang == strMaPhieuNhap
                              select new NhapHang_BAL()
                              {
                                  MaNhapHang = pnh.MaNhapHang,
                                  TrangThai = (int)pnh.TrangThai
                              };
                result = phieuNH.ToList<NhapHang_BAL>();
            }
            catch
            {

            }
            return result;
        }

        public static void Insert(NhapHang_BAL nhapHang)
        {
            Common_DAL.storeData.TaoPhieuNhapHang(nhapHang.MaNhapHang);
            Common_DAL.storeData.SubmitChanges();
        }
    }
}
